package com.qf.controller;

import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import com.qf.vo.DayStatis;
import com.qf.vo.StatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.crypto.Data;
import java.util.*;

@CrossOrigin("*")
@RestController
@RequestMapping("/admin/stat")
public class AdminStatController {

    @Autowired
    DtsUserService userService;

    private static final int STATIS_DAYS_RANG = 30;

    @RequestMapping("/user")
    public Object user(){

        List<DayStatis> userStatis = userService.queryDayStatis(STATIS_DAYS_RANG);
        List<Map> list = new ArrayList<>();
        for (DayStatis userStati : userStatis) {
            Map<String, Object> map = new HashMap<>();
            map.put("day",userStati.getDayStr());
            map.put("users",userStati.getCnts());
            list.add(map);
        }
        StatVo statVo = new StatVo();

        String [] s = {"day","users"};

        statVo.setColumns(s);
        statVo.setRows(list);

        return ResponseUtil.ok(statVo);
    }
}
